Imports System.Threading
Imports System.Web

Friend Class UserInfo

#Region "Get IP"

	Friend Shared Function GetUserIP() As String

		If Utils.AssemblyUtil.GetAppType = Utils.AppTypeEnum.AspNet Then
			Return GetUserIP_AspNet()
		Else
			Return GetUserIP_WindowsForms()
		End If

	End Function

	Friend Shared Function GetUserIP_AspNet() As String

		Try
			Return HttpContext.Current.Request.UserHostAddress
		Catch
			Return My.Resources.Messages.Undefined
		End Try

	End Function

	Friend Shared Function GetUserIP_WindowsForms() As String

		Try

			Dim strIP As String = String.Empty
			Dim arrIP() As Net.IPAddress
			Dim i As Integer

			arrIP = Net.Dns.GetHostEntry(Net.Dns.GetHostName).AddressList()

			For i = 0 To arrIP.Length - 1
				If Not Net.IPAddress.IsLoopback(arrIP(i)) Then
					strIP = arrIP(i).ToString()
				End If
			Next

			If strIP.Length < 1 Then
				strIP = arrIP(0).ToString()
			End If

			Return strIP

		Catch

			Return My.Resources.Messages.Undefined

		End Try

	End Function

#End Region

#Region "Get language"

	Friend Shared Function GetUserLanguage() As String

		Try
			Return Thread.CurrentThread.CurrentUICulture.Name
		Catch
			Try
				Return Thread.CurrentThread.CurrentCulture.Name
			Catch
				Return My.Resources.Messages.Undefined
			End Try
		End Try

	End Function

#End Region

End Class